const express = require('express')
const validate = require('express-validation')
const _ = require('lodash')
const moment = require('moment')
const managerController = require('../controller/managerController')

const managerRouter = express.Router()

managerRouter.post('/login', async (req, res, next) => {
  const { managerId, password } = req.body
  const loginTime = new Date()
  const outdateTime = new Date(loginTime.getTime() + 12 * 3600 * 1000) // token有效期：12小时
  try {
    const result = await managerController.login({ managerId, password, loginTime, outdateTime })
    res.json({ status: 200, msg: '登录成功', data: result })
  } catch (e) {
    next(e)
  }
})

module.exports = managerRouter
